var tabclick;
var malltab2, getphone, user, malltab3, malltab4;
var grid, grid3;
var editadmin, exportadmin;
var showorderstatus;
var searchOrderInfor, end_time, start_time, start_time_data, end_time_data;
var orderstatusdata = [{
    name: 'DONE',
    display: '完成'
}, {
    name: 'CANCELED',
    display: '取消'
}, {
    name: 'UNCONFIRMED',
    display: '未确认'
}, {
    name: 'ORDERED',
    display: '已下单'
}, {
    name: 'PRODUCING',
    display: '生产中'
}, {
    name: 'TRANSPORTING',
    display: '运输中'
}, {
    name: 'DISPATCHING',
    display: '配送中'
}, {
    name: 'VERIFY_FAILED',
    display: '鉴伪失败'
}];
angular.module('account', ['ng'])
    .controller('accountCtrl', ['$scope', '$http',
        function ($scope) {
            $scope.malldata;
            user = JSON.parse(localStorage.getItem("user"));
            //
            var getmalldata = function () {
                var param = {
                    mall_id: user.mall_id
                };
                $.ajax({
                    type: "GET",
                    url: commonobj.ip + "mall/info",
                    dataType: "json",
                    contentType: "application/json",
                    data: param,
                    success: function (data) {
                        if (data.msg == "success") {
                            $scope.malldata = data.data;
                            for (var i = 0; i < $scope.malldata.devices.length; i++) {
                                $scope.malldata.devices[i].web_bind_timestamp = commonobj.timeservice($scope.malldata.devices[i].bind_timestamp);
                            }
                            $scope.$apply()
                        }
                    },
                    error: function (data) {
                        $('#resetpwd1').hide();
                        $('#modalmsg').show();
                        $('#contentmsg').html(data.responseJSON.msg);
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }

                    }
                });
            };
            var getproductdata = function () {
                $.ajax({
                    type: "GET",
                    url: commonobj.ip + "/product/query",
                    dataType: "json",
                    contentType: "application/json",
                    success: function (data) {
                        if (data.msg == "success") {
                            $scope.productdata = data.data;
                        } else {
                            $scope.productdata = [];
                        }
                    },
                    error: function (data) {
                        $scope.productdata = [];
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }

                    }
                });
            };
            $scope.showtab = 'userinfo';
            tabclick = function (e, name) {
                $('#myTab li').removeClass('active');
                $(e).addClass('active');
                $('#myTabContent .tab-pane').removeClass('active');
                $('#myTabContent .tab-pane').removeClass('in');
                $('#' + name).addClass('active');
                $('#' + name).addClass('in');
                if (name == "eleinfo") {
                    getmalldata();
                } else if (name == "malldetail") {
                    malltab2.recommend();
                } else if (name == "employee") {
                    malltab3.recommend();
                } else if (name == "order") {
                    start_time = $("#start_time").ligerDateEditor(
                        {

                            format: "yyyy-MM-dd hh:mm:ss",
                            label: '开始时间',
                            labelWidth: 80,
                            //width:140,
                            labelAlign: 'center',
                            cancelable: true,
                            showTime: true
                        });
                    end_time = $("#end_time").ligerDateEditor(
                        {

                            format: "yyyy-MM-dd hh:mm:ss",
                            label: '结束时间',
                            labelWidth: 80,
                            //width:140,
                            labelAlign: 'center',
                            cancelable: true,
                            showTime: true
                        });
                    malltab4.recommend();
                }
            };
            searchOrderInfor = function () {
                malltab4.recommend();
            };
            //malltab2
            malltab2 = {
                recommend: function () {
                    var grid = $("#maingrid2").ligerGrid({
                        url: commonobj.ip + 'recommend/list',
                        method: "get",
                        parms: [
                            {name: 'mall_id', value: user.mall_id}
                        ],
                        root: 'list',
                        record: 'total',
                        pageParmName: 'start',
                        pagesizeParmName: 'limit',
                        width: '98%',
                        height: '98%',
                        pageSize: 10,
                        pageSizeOptions: [10, 20, 30, 50],
                        rownumbers: true,
                        columns: [
                            {display: '门店名称', name: 'mall_name', align: 'left', width: "10%"},
                            {display: '用户名称', name: 'user_name', align: 'left', width: "10%"},
                            {
                                display: '电话', name: 'phone',
                                render: function (rowdata, rowindex, value) {
                                    var str = JSON.stringify(rowdata);
                                    var html = '';
                                    html +=
                                        "<a class='text-primary operate_text' onclick='getphone.getphonefun(" + str + ")'>获取电话</a>&nbsp;&nbsp;";
                                    return html;
                                }
                            },
                            {display: '年龄', name: 'age_value', align: 'left'},
                            {
                                display: '性别', name: 'gender_value', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == 0) {
                                        return "男";
                                    } else if (value == 1) {
                                        return "女";
                                    }
                                }
                            },
                            {display: '身高(cm)', name: 'height_value', align: 'left'},
                            {display: '体重(kg)', name: 'weight_value', align: 'left'},
                            {
                                display: 'bmi指数', name: 'bmi_value', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    return parseInt(value, 10);
                                }
                            },
                            {
                                display: '怀孕状态', name: 'pregnant_value', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == 0) {
                                        return "备孕";
                                    } else if (value == 1) {
                                        return "备孕";
                                    } else if (value == 2) {
                                        return "产后2年内";
                                    } else if (value == 3) {
                                        return "无";
                                    }
                                }
                            },
                            {display: 'psqi得分', name: 'psqi_value', align: 'left'},
                            {
                                display: '推荐产品型号', name: 'recommended_mattress_production', align: 'left', width: '15%',
                                render: function (rowdata, rowindex, value) {
                                    var str = "";
                                    for (var i = 0; i < value.length; i++) {
                                        if (i == 0) {
                                            str += value[i].name;
                                        } else {
                                            str += ',' + value[i].name;
                                        }
                                    }
                                    return str;
                                }
                            },
                            {
                                display: '体验时间', name: 'timestamp', align: 'left', width: "10%",
                                render: function (rowdata, rowindex, value) {
                                    return commonobj.timeservice(value);
                                }
                            },
                            {
                                display: '操作',
                                render: function (rowdata, rowindex, value) {
                                    var str = JSON.stringify(rowdata);
                                    var html = '';
                                    html +=
                                        "<a class='text-primary operate_text' onclick='malltab2.detailsmodal( " + str + ")'>详情</a>";
                                    return html;
                                }
                            }
                        ]
                    });
                    grid.bind('Success', function (data) {
                        if (data.list == null || data.list.length == 0) {
                            $("#zwsj2").show();
                        } else {
                            $("#zwsj2").hide();
                        }
                    });
                    grid.bind('Error', function (data) {
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }

                    });

                },
                detailsmodal: function (obj) {
                    $('#modaldetails').show();
                    $scope.deviceObj = angular.copy(obj);
                    $scope.deviceObj.bmi_value = parseInt($scope.deviceObj.bmi_value, 10);
                    $scope.$apply();
                },
                canceldetailmodal: function () {
                    $('#modaldetails').hide();
                }
            };
            //malltab3


            malltab3 = {
                recommend: function () {
                    var grid3 = $("#maingrid3").ligerGrid({
                        url: commonobj.ip + 'wx/mall_employer/query',
                        method: "get",
                        parms: [
                            {name: 'mall_id', value: user.mall_id}
                        ],
                        root: 'data',
                        record: 'total',
                        pageParmName: 'start',
                        pagesizeParmName: 'limit',
                        width: '98%',
                        height: '98%',
                        pageSize: 10,
                        pageSizeOptions: [10, 20, 30, 50],
                        rownumbers: true,
                        columns: [
                            {
                                display: '用户名称', name: 'nick', width: "12%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {display: '门店ID', name: 'mall_id', width: "15%"},
                            {
                                display: '性别', name: 'gender', width: "10%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == "male") {
                                        return "男";
                                    } else if (value == "female") {
                                        return "女";
                                    } else if (value == null) {
                                        return "--";
                                    }
                                }
                            },
                            {
                                display: '电话', name: 'phone', width: "12%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {
                                display: '国家', name: 'country', width: "12%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {
                                display: '省', name: 'province', width: "12%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {
                                display: '市', name: 'city', width: "12%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {
                                display: '状态', name: 'status', width: "15%",
                                render: function (rowdata, rowindex, value) {
                                    if (value == "NORMAL") {
                                        return "正常";
                                    } else if (value == "VACATION") {
                                        return "休假";
                                    } else if (value == "QUIT") {
                                        return "辞职";
                                    } else if (value == null) {
                                        return "--";
                                    }

                                }
                            }

                        ]


                    });
                    grid3.bind('Success', function (data) {
                        if (data.data == null || data.data.length == 0) {
                            $("#zwsj3").show();
                        } else {
                            $("#zwsj3").hide();
                        }
                    });
                    grid3.bind('Error', function (data) {
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }

                    });

                }

            };
            //malltab4
            malltab4 = {
                recommend: function () {
                    var paramSearch = {};
                    paramSearch.mall_id = user.mall_id;
                    start_time_data = $("#start_time").val();
                    end_time_data = $("#end_time").val();
                    var user_name = $.trim($('#user_name').val());
                    var mall_employer_name = $.trim($('#employer_name').val());
                    if (start_time_data != "") {
                        paramSearch.st = new Date(start_time_data).getTime();
                    }
                    if (end_time_data != "") {
                        paramSearch.et = new Date(end_time_data).getTime();
                    }
                    if (user_name != "") {
                        paramSearch.user_name = user_name;
                    }
                    if (mall_employer_name != "") {
                        paramSearch.mall_employer_name = mall_employer_name;
                    }
                    var grid4 = $("#maingrid4").ligerGrid({
                        url: commonobj.ip + 'order/query',
                        method: "get",
                        urlParms: paramSearch,
                        root: 'data',
                        //record: 'total',
                        pageParmName: 'start',
                        pagesizeParmName: 'limit',
                        width: '100%',
                        height: '98%',
                        pageSize: 10,
                        pageSizeOptions: [10, 20, 30, 50],
                        rownumbers: false,
                        columns: [
                            {display: '订单ID', name: 'id', align: 'left', width: "10%"},
                            {
                                display: '订单类型', name: 'is_custom', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value) {
                                        return "定制订单";
                                    } else {
                                        return "产品订单";
                                    }
                                }
                            },
                            {display: '门店名称', name: 'mall_name', align: 'left'},
                            {display: '用户名称', name: 'user_name', align: 'left'},
                            {
                                display: '订单下单雇员名', name: 'mall_employer_name', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {display: 'recommend_report_id', name: 'recommend_report_id', align: 'left'},
                            {
                                display: '邮寄地址', name: 'deliver_address', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == null) {
                                        return "--";
                                    } else {
                                        return value;
                                    }
                                }
                            },
                            {
                                display: '下单时间', name: 'create_timestamp', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == 0 || value == null) {
                                        return "--";
                                    } else {
                                        return commonobj.timeservice(value);
                                    }
                                }
                            },
                            {
                                display: '状态更新时间', name: 'update_timestamp', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == 0 || value == null) {
                                        return "--";
                                    } else {
                                        return commonobj.timeservice(value);
                                    }
                                }
                            },
                            {
                                display: '状态', name: 'status', align: 'left',
                                render: function (rowdata, rowindex, value) {
                                    if (value == "UNCONFIRMED") {
                                        return "未确认";
                                    } else if (value == "ORDERED") {
                                        return "已下单";
                                    } else if (value == "PRODUCING") {
                                        return "生产中";
                                    } else if (value == "TRANSPORTING") {
                                        return "运输中";
                                    } else if (value == "DISPATCHING") {
                                        return "配送中";
                                    } else if (value == "DONE") {
                                        return "完成";
                                    } else if (value == "CANCELED") {
                                        return "取消";
                                    } else if (value === "VERIFY_FAILED") {
                                        return "鉴伪失败";
                                    } else {
                                        return value;
                                    }

                                }
                            },
                            {
                                display: '操作',
                                render: function (rowdata, rowindex, value) {
                                    var str = JSON.stringify(rowdata);
                                    var html = '';
                                    html +=
                                        "<a class='text-primary operate_text' onclick='editadmin.show(" + str + ")'>编辑</a>&nbsp;&nbsp;" +
                                        "<a class='text-primary operate_text' onclick='exportadmin.export( " + str + ")'>导出</a>";
                                    return html;
                                }
                            }
                        ],
                        detail: {onShowDetail: f_showOrder}
                    });
                    grid4.bind('Success', function (data) {
                        $scope.orderData = [];
                        if (data.data == null || data.data.length == 0) {
                            $("#zwsj4").show();
                        } else {
                            $scope.orderData = data.data;
                            for (var i = 0; i < $scope.orderData.length; i++) {
                                if (!$scope.orderData[i].is_custom) {
                                    for (var j = 0; j < $scope.orderData[i].production_list.length; j++) {
                                        $scope.orderData[i].production_list[j].product_name = getproductionname($scope.orderData[i].production_list[j].product_code);
                                    }
                                }

                            }
                            $("#zwsj4").hide();
                        }
                    });
                    grid4.bind('Error', function (data) {
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }

                    });
                }


            };

            function f_getOrdersData(CustomerID) {
                var AllOrdersData = $scope.orderData;
                var data = {Rows: []};
                for (var i = 0; i < AllOrdersData.length; i++) {
                    if (AllOrdersData[i].id == CustomerID) {
                        data.Rows = AllOrdersData[i].is_custom ? AllOrdersData[i].custom_list : AllOrdersData[i].production_list;
                        break;
                    }
                }
                return data;
            }

//显示顾客订单
            function f_showOrder(row, detailPanel, callback) {
                var grid = document.createElement('div');
                $(detailPanel).append(grid);
                if (!row.is_custom) {
                    $(grid).css('margin', 40).ligerGrid({
                        columns:
                            [
                                {
                                    display: '产品名称', name: 'product_name', type: 'float', width: '20%', minWidth: 200
                                },
                                {display: '订单ID', name: 'order_id', type: 'float', width: '20%', minWidth: 200},
                                {
                                    display: '产品创建时间',
                                    name: 'create_timestamp',
                                    type: 'float',
                                    width: '20%',
                                    minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        if (value == 0 || value == null) {
                                            return "--";
                                        } else {
                                            return commonobj.timeservice(value);
                                        }
                                    }
                                },
                                {
                                    display: '产品更新时间', name: 'update_timestamp', width: '20%', minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        if (value == 0 || value == null) {
                                            return "--";
                                        } else {
                                            return commonobj.timeservice(value);
                                        }
                                    }
                                },
                                {
                                    display: '产品状态', name: 'status', width: '20%', minWidth: 200,
                                    render: function (rowdata, rowindex, value) {
                                        if (value == "NOT_VERIFIED") {
                                            return "未鉴伪";
                                        } else if (value == "PASSED") {
                                            return "鉴伪通过";
                                        } else if (value == "VERIFICATION_TOKEN_ABSENT") {
                                            return "鉴伪码不存在";
                                        } else if (value == "VERIFICATION_PRODUCT_MISMATCH") {
                                            return "鉴伪码型号不匹配";
                                        } else if (value == "VERIFICATION_TOKEN_ALREADY_USED") {
                                            return "鉴伪码失效";
                                        }

                                    }
                                }
                            ],
                        isScroll: false,
                        showToggleColBtn: false,
                        width: '90%',
                        height: '98%',
                        data: f_getOrdersData(row.id),
                        showTitle: false,
                        onAfterShowData: callback,
                        frozen: false
                    });
                } else {
                    $(grid).css('margin', 40).ligerGrid({
                        columns:
                            [
                                {
                                    display: 'NO',
                                    name: 'idx',
                                    width: '5%',
                                    minWidth: 50,
                                    height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == null) {
                                            tempValue = "--";
                                        } else {
                                            tempValue = value + 1;
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '尺寸', name: 'chicun', width: '5%', minWidth: 80, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html = "<div style='line-height:120px;'>180*200</div>";
                                        return html;

                                    }
                                },
                                {
                                    display: '订单ID', name: 'order_id', width: '10%', minWidth: 200, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + value +
                                            "</div>";
                                        return html;

                                    }
                                },
                                {
                                    display: '创建时间',
                                    name: 'create_timestamp',
                                    width: '10%',
                                    minWidth: 150,
                                    height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == 0 || value == null) {
                                            tempValue = "--";
                                        } else {
                                            tempValue = commonobj.timeservice(value);
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '更新时间', name: 'update_timestamp', width: '10%', minWidth: 150, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == 0 || value == null) {
                                            tempValue = "--";
                                        } else {
                                            tempValue = commonobj.timeservice(value);
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '定制规格', columns: [{
                                        display: '定制层', name: 'order_id', width: 100, height: 40,
                                        render: function (rowdata, rowindex, value) {
                                            var str = JSON.stringify(rowdata);
                                            var html = '';
                                            html +=
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "弹簧层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "柔软层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "亲肤层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "面料层" +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + "工艺" +
                                                "</div>" +
                                                "<div style='height:20px;text-align: center;'>" + "硬质层" +
                                                "</div>";
                                            return html;
                                        }
                                    }, {
                                        display: '编码', name: 'order_id', width: 100, height: 40,
                                        render: function (rowdata, rowindex, value) {
                                            var html = '';
                                            var support_code = rowdata.support_code || "--";
                                            var soft_code = rowdata.soft_code || "--";
                                            var skin_code = rowdata.skin_code || "--";
                                            var surface_code = rowdata.surface_code || "--";
                                            var craft_code = rowdata.craft_code || "--";
                                            var hard_code = rowdata.hard_code || "--";
                                            html +=
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + support_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + soft_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + skin_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + surface_code +
                                                "</div>" +
                                                "<div style='height:20px;border-bottom: 1px solid #DFDFDF;text-align: center;'>" + craft_code +
                                                "</div>" +
                                                "<div style='height:20px;text-align: center;'>" + hard_code +
                                                "</div>";
                                            return html;
                                        }
                                    }, {
                                        display: '名称', name: 'order_id', width: 200, height: 40,
                                        render: function (rowdata, rowindex, value) {
                                            var str = JSON.stringify(rowdata);
                                            var html = '';
                                            var support_name = rowdata.support_detail ? rowdata.support_detail.name : "--";
                                            var soft_name = rowdata.soft_detail ? rowdata.soft_detail.name : "--";
                                            var skin_name = rowdata.skin_detail ? rowdata.skin_detail.name : "--";
                                            var surface_name = rowdata.surface_detail ? rowdata.surface_detail.name : "--";
                                            var craft_name = rowdata.craft_detail ? rowdata.craft_detail.name : "--";
                                            var hard_name = rowdata.hard_detail ? rowdata.hard_detail.name : "--";
                                            html +=
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + support_name + "'>" + support_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + soft_name + "' >" + soft_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + skin_name + "'>" + skin_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + surface_name + "'>" + surface_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;border-bottom: 1px solid #DFDFDF;text-align: center;' title='" + craft_name + "'>" + craft_name +
                                                "</div>" +
                                                "<div style='height:20px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;text-align: center;' title='" + hard_name + "'>" + hard_name +
                                                "</div>";
                                            return html;
                                        }
                                    }]
                                },
                                {
                                    display: '折扣率', name: 'rate', width: '10%', minWidth: 50, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html = "<div style='line-height:120px;'>100%</div>";
                                        return html;
                                    }
                                },
                                {
                                    display: '金额',
                                    name: 'total_price',
                                    type: 'float',
                                    width: '10%',
                                    minWidth: 100,
                                    height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + value +
                                            "</div>";
                                        return html;

                                    }
                                },
                                {
                                    display: '产品状态', name: 'status', width: '10%', minWidth: 100, height: 40,
                                    render: function (rowdata, rowindex, value) {
                                        var tempValue;
                                        if (value == "NOT_VERIFIED") {
                                            tempValue = "未鉴伪";
                                        } else if (value == "PASSED") {
                                            tempValue = "鉴伪通过";
                                        } else if (value == "VERIFICATION_TOKEN_ABSENT") {
                                            tempValue = "鉴伪码不存在";
                                        } else if (value == "VERIFICATION_PRODUCT_MISMATCH") {
                                            tempValue = "鉴伪码型号不匹配";
                                        } else if (value == "VERIFICATION_TOKEN_ALREADY_USED") {
                                            tempValue = "鉴伪码失效";
                                        }
                                        var html = '';
                                        html +=
                                            "<div style='line-height:120px;'>" + tempValue +
                                            "</div>";
                                        return html;
                                    }
                                }
                            ],
                        isScroll: false,
                        showToggleColBtn: false,
                        width: '90%',
                        rowHeight: 120,
                        data: f_getOrdersData(row.id),
                        showTitle: false,
                        onAfterShowData: callback,
                        frozen: false
                    });
                }


            }

            function getproductionname(value) {
                var productname = "--";
                for (var i = 0; i < $scope.productdata.length; i++) {
                    if (value === $scope.productdata[i].code) {
                        productname = $scope.productdata[i].name;
                    }
                }
                return productname;
            }

            $scope.logout = function () {
                localStorage.setItem("user", "");
                window.document.location.href = commonobj.getRootPath() + '/views/login.html';
            };

            //修改密码
            $scope.editpassword = function () {
                $('#modal').show();
            };
            $scope.oldpw = '';
            $scope.newpw = '';
            $scope.aginload = '';
            $scope.savepassword = function () {
                if ($scope.oldpw != '' && $scope.newpw != '') {
                    var param = {
                        id: user.mall_id,
                        pwd: $scope.newpw,
                        old_pwd: $scope.oldpw
                    };
                    $.ajax({
                        type: "post",
                        url: commonobj.ip + "mall/update",
                        dataType: "json",
                        contentType: "application/json",
                        data: JSON.stringify(param),
                        success: function (data) {
                            if (data.msg == "success") {
                                $('#modal1').show();
                                $('#content').html('密码修改成功，请重新登录！');
                            }
                        },
                        error: function (data) {
                            $('#modal1').show();
                            $('#content').html(data.responseJSON.msg);
                            if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                commonobj.sessionExpired();
                            }

                        }
                    });
                } else {
                    $('#modal1').show();
                    $('#content').html('密码不能为空！');
                }
            };
            $scope.loadagain = function () {
                localStorage.setItem("sqsuser", "");
                window.parent.parent.location.href = commonobj.getRootPath() + '/views/login.html';
            };
            showpass = function (a) {
                if ($(a).parent().find('input').attr('type') == 'password') {
                    $(a).parent().find('input').attr('type', 'text');
                    $(a).find('.icon').removeClass('wb-eye-close');
                    $(a).find('.icon').addClass('wb-eye');
                } else {
                    $(a).parent().find('input').attr('type', 'password');
                    $(a).find('.icon').removeClass('wb-eye');
                    $(a).find('.icon').addClass('wb-eye-close');
                }
            };
            closebackmsg = function () {
                if ($('#modal').is(':visible')) {
                    if ($('#modal1').is(':visible')) {
                        $('#modal1').hide();
                    } else {
                        $('#modal').hide();
                    }
                }
            };
            var init = function () {
                $(document).ready(function () {
                    $('#right').width($(document).width() - 185 - 30);
                });
                var user = localStorage.getItem("user");
                if (user == null || user == "") {
                    window.document.location.href = commonobj.getRootPath() + '/views/login.html';
                }
                getmalldata();
                getproductdata();
            };
            init();
            //getphone
            $scope.okbtn = true;
            getphone = {
                data: null,
                getphonefun: function (obj) {
                    getphone.data = obj;
                    $.get(commonobj.ip + "audit/count?account_id=" + user.mall_id + "&user_id=" + obj.user_id).success(function (data) {
                        if (data.code == "0") {
                            $('#modalphone').show();
                            if (data.data.used_number < 2) {
                                var html = '<p style="color: #f00;">请勿滥用客户电话信息，如造成客户投诉，会导致门店账号被查封。</p>' +
                                    '<p>最多获取电话次数：' + data.data.max_number + '次</p>' +
                                    '<p>已经获取电话次数：<span>' + data.data.used_number + '次</span></p>';
                                $('#contentphone').html(html);
                                $scope.$apply(function () {
                                    $scope.okbtn = false;
                                });
                            } else {
                                var html1 = '<p style="color: #f00;">请勿滥用客户电话信息，如造成客户投诉，会导致门店账号被查封。</p>' +
                                    '<p>最多获取电话次数：' + data.data.max_number + '次</p>' +
                                    '<p>已经获取电话次数：<span>' + data.data.used_number + '次</span></p>' +
                                    '<p>不能再继续获取</p>';
                                $('#contentphone').html(html1);
                                $scope.$apply(function () {
                                    $scope.okbtn = true;
                                });
                            }
                        }
                    }).error(function (data) {
                        $('#modalphone').hide();
                        $('#modalmsg').show();
                        $('#contentmsg').html(data.responseJSON.msg);
                        if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                            commonobj.sessionExpired();
                        }


                    });
                },
                cancelfun: function () {
                    $('#modalphone').hide();
                },
                okphone: function () {
                    var param = {
                        "account_id": user.mall_id,
                        "user_id": getphone.data.user_id
                    };
                    $.ajax({
                        type: "post",
                        url: commonobj.ip + "audit/phone",
                        dataType: "json",
                        contentType: "application/json",
                        data: JSON.stringify(param),
                        success: function (data) {
                            if (data.msg == "success") {
                                $('#modalphone').show();
                                var html = '<p>电话号码：<span>' + data.data.phone + '</span></p>';
                                $('#contentphone').append(html);
                                $scope.$apply(function () {
                                    $scope.okbtn = true;
                                });
                            }
                        },
                        error: function (data) {
                            html += '<p>电话号码：<span>获取失败</span></p>';
                            $('#contentphone').html(html);
                            if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                commonobj.sessionExpired();
                            }


                        }
                    });
                }
            };
            $scope.showStatusOption = false;
            editadmin = {
                data: null,
                show: function (obj) {
                    showorderstatus();
                    $scope.showStatusOption = true;
                    editadmin.data = obj;
                    obj.create_timestamp = obj.create_timestamp ? commonobj.timeservice(obj.create_timestamp) : "--";
                    obj.update_timestamp = obj.update_timestamp ? commonobj.timeservice(obj.update_timestamp) : "--";
                    $scope.$apply(function () {
                        $scope.editdata = obj;
                    });
                    type = "edit";
                    var statusTemp = "=请选择状态=";
                    orderstatusdata.forEach(function (item, index) {
                        if (item.name === obj.status) {
                            statusTemp = index;
                        }
                    });
                    $('#editmodaldetails').show();
                    $('#editmodaldetails .title').html('编辑订单状态');
                    $('#orderstatus').val(statusTemp);
                },
                okfun: function () {
                    if ($('#orderstatus').val() !== "") {
                        var statusval = orderstatusdata[$('#orderstatus').val()].name;
                        var param = {
                            "id": editadmin.data.id,
                            "status": statusval
                        };
                        $.ajax({
                            type: "put",
                            url: commonobj.ip + "order/update/order/status",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify(param),
                            success: function (data) {
                                if (data.msg == "success") {
                                    $('#editmodaldetails').hide();
                                    $('#editmodalcontent').html("");
                                    $('#editmodalresult').show();
                                    $('#editmodalcontent').html("编辑成功");
                                    malltab4.recommend();
                                }
                            },
                            error: function (data) {
                                $('#editmodaldetails').hide();
                                $('#editmodalcontent').html("");
                                $('#editmodalresult').show();
                                $('#editmodalcontent').html(data.responseJSON.msg);
                                if (JSON.parse(data.responseText).code && JSON.parse(data.responseText).code === "1010") {
                                    commonobj.sessionExpired();
                                }

                            }
                        });
                    } else {
                        $('#editmodalcontent').html("");
                        $('#editmodalresult').show();
                        $('#editmodalcontent').html("请选择状态");
                    }
                },
                cancelfun: function () {
                    $('#editmodaldetails').hide();
                },
                closebackmsg: function () {
                    $('#editmodalresult').hide();
                }
            };
            exportadmin = {
                export: function (data) {
                    window.open(commonobj.ip + "order/export/" + data.id);
                }
            };
            showorderstatus = function () {
                if ($scope.showStatusOption) {
                    return;
                }
                var len = orderstatusdata.length;
                for (var i = 0; i < len; i++) {
                    var provOpt = document.createElement('option');
                    provOpt.innerText = orderstatusdata[i]['display'];
                    provOpt.value = i;
                    provOpt.setAttribute('text', provOpt.innerText);
                    $('#orderstatus').append(provOpt);
                }
            };
        }

    ]);
$(document).ready(function () {
    $('#right').width($(document).width() - 185 - 30);
    var user = localStorage.getItem("user");
    if (user == null || user == "") {
        window.document.location.href = commonobj.getRootPath() + '/views/login.html';
    }
});
var closebackmsg = function () {
    $('#modalmsg').hide();
};
